#include <gtk/gtk.h>
#include <stdio.h>

void sayHello() {
    printf("hello word\n");
}

guint timer = 0;//定时器id

void set_widget_font_size(GtkWidget *label, int size, int is_button) {
    GtkWidget *labelChild;    
    PangoFontDescription *font;    
    gint fontSize = size;    
    
    font = pango_font_description_from_string("Sans");//"Sans"字体名     
    pango_font_description_set_size(font, fontSize*PANGO_SCALE);//设置字体大小     
    
    if(is_button){  
        // labelChild = gtk_bin_get_child(GTK_BIN(widget));//取出GtkButton里的label    
    }else{  
        labelChild = label;
    }  
    
    //设置label的字体，这样这个GtkButton上面显示的字体就变了  
    // gtk_widget_modify_font(GTK_WIDGET(labelChild), font);
    pango_font_description_free(font);  

}


gboolean deal_time( gpointer* label )   
{  
    char buf[5] = "";  
    static int num = 10;  
    num--;  
    sprintf(buf, "%d", num);  
    gtk_label_set_text(GTK_LABEL(label), buf);  

    if(0 == num){  
        num = 11;  
        //g_source_remove(timer); // 移除定时器   
    }  

    return TRUE;//尽量返回TRUE  
}

static void activate(GtkApplication *app, gpointer user_data) {
    GtkWidget *window;
    GtkWidget *button;

    window = gtk_application_window_new(app);
    // 设置窗口标题
    gtk_window_set_title(GTK_WINDOW(window), "template");
    // 设置窗口大小
    gtk_window_set_default_size(GTK_WINDOW(window), 400,320);

    GtkLabel *label = (GtkLabel*)gtk_label_new("10");
    set_widget_font_size(GTK_WIDGET(label), 230, FALSE);

    timer = g_timeout_add(500, (GSourceFunc)deal_time, (gpointer)label);

    gtk_window_set_child(GTK_WINDOW(window), GTK_WIDGET(label));
    gtk_widget_show(window);
}

int	main(int argc, char **argv) {

    GtkApplication *app;
    int status;

    app = gtk_application_new("gtk.example.template", G_APPLICATION_FLAGS_NONE);
    g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
    status = g_application_run(G_APPLICATION(app), argc, argv);
    g_object_unref(app);

    return status;
}

